using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Web.WebForm.WWW.Files
{
    public class UploFileProcBarDo : System.Web.UI.Page
    {
        protected Panel pnlProgress;
        protected Label labCompleted;
        protected Label progressBar;

        protected override void OnLoad(EventArgs e)
        {
            if ((!string.IsNullOrEmpty(Request["C"])) || (!string.IsNullOrEmpty(Request["C1"])))
            {
                pnlProgress.Visible = false;
                Page.ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script type=\"text/javascript\">parent.document.getElementById(\'divFileUploProcBar\').style.display=\'none\';parent.document.getElementById(\'divFileUploSucc\').style.display=\'\';</script>");
                return;
            }
            if (!string.IsNullOrEmpty(Request["LongxinUploadGUID"]))
            {
                Lx.Progress obj = (Lx.Progress)Application["_UploadGUID_" + Request["LongxinUploadGUID"]];
                if (obj != null)
                {
                    if (!(obj.UploadStatus == Lx.Progress.UploadStatusEnum.Completed))
                    {
                        obj.RemoveUploadID();
                        Double k = (double)obj.FileLength / 1048576;
                        string a = ((double)obj.ReceivedLength / (double)obj.FileLength).ToString("P");
                        progressBar.Style["width"] = a;
                        labCompleted.Text = String.Format("{0}(Size:{1}M)", a, k.ToString("#####.##"));
                        pnlProgress.Visible = true;
                        if (((double)obj.ReceivedLength / (double)obj.FileLength) < 0.99)
                        {
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script type=\"text/javascript\">window.setTimeout(\"window.location.href=window.location.href\", 1000);</script>");
                        }
                        else
                        {
                            obj.RemoveUploadID();
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script type=\"text/javascript\">window.setTimeout(\"window.location.href=window.location.href+\'&C=1\'\", 1000);</script>");
                        }
                    }
                    else
                    {
                        obj.RemoveUploadID();
                        labCompleted.Text = "Complete";
                        pnlProgress.Visible = false;
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script type=\"text/javascript\">window.setTimeout(\"window.location.href=window.location.href+\'&C1=1\'\", 1000);</script>");
                    }
                }
                else
                {
                    pnlProgress.Visible = false;
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script type=\"text/javascript\">window.setTimeout(\"window.location.href=window.location.href\", 1000);</script>");
                }
            }
            base.OnLoad(e);
        }
    }
}
